<template>
  <div class="layout">
    <DataBar :crumbs="crumbs" style="margin-bottom: 30px"></DataBar>
    <SelectBox
      @changeOption="changeOption"
      style="margin-bottom: 30px"
      :width="1200"
      :type="'redemption'"
    ></SelectBox>
    <div id="policyDiv">
      <div id="searchDiv">
        <div id="selectBar">
          <div id="leftSelectDiv">
            <div class="selectOptionDiv" @click="changeShowDateOrder">
              <div style="margin-right: 5px">发布时间</div>
              <img v-show="orderShowDate %3 == 0" src="@/assets/image/policyList/orderIcon.png" />
              <img v-show="orderShowDate %3 == 1" src="@/assets/image/policyList/orderDescIcon.png" />
              <img v-show="orderShowDate %3 == 2" src="@/assets/image/policyList/orderAscIcon.png" />
            </div>
            <span class="divide">|</span>
            <div class="selectOptionDiv" @click="changePvOrder">
              <div style="margin-right: 5px">浏览量</div>
              <img v-show="orderPv %3 == 0" src="@/assets/image/policyList/orderIcon.png" />
              <img v-show="orderPv %3 == 1" src="@/assets/image/policyList/orderDescIcon.png" />
              <img v-show="orderPv %3 == 2" src="@/assets/image/policyList/orderAscIcon.png" />
            </div>
          </div>
          <div id="rightDiv">
            <el-select v-model.trim="status" @change="getSearchPolicys">
              <el-option
                v-for="statu in statusOption"
                :value="statu.value"
                :label="statu.label"
                :key="statu.value"
              ></el-option>
            </el-select>
            <div @click="toPrevPage()" :class="pageNum <= 1 ? 'pageBtn  pageCantBtn' : 'pageBtn'"><</div>
            <div @click="toNextPage()" :class="isLastPage() ? 'pageBtn  pageCantBtn' : 'pageBtn'">></div>
          </div>
        </div>
        <div id="policyListDiv">
          <PolicyFrame
            v-for="(policy, index) in policys"
            :policy="policy"
            :index="index"
            :key="policy.id"
          ></PolicyFrame>
        </div>
        <div id="policyPagination" v-if="total > 0">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageNum"
            background
            :page-sizes="[10, 20, 30, 50]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </div>
      <div id="showingDiv">
        <div class="showTitle">| 兑现结果公示</div>
        <div
          class="announceDiv"
          @click="$router.push({path: 'policyDetail', query: {id: announce.policyId, selectTypeIndex: 2, item: '1' }})"
          v-for="(announce, index) in announces"
          :key="index"
          :style="index == announces.length - 1 ? 'border-bottom: 0px; padding-bottom: 0' : ''"
        >
          <div class="policyDate">{{announce.policyNo}}</div>

          <div class="policyName">{{announce.policyName}}</div>
          <!-- <div class="policyType" :style="'color: ' + formatLabel(announce.policyTypeName).color + '; background-color: ' + formatLabel(announce.policyTypeName).bgColor">{{formatLabel(announce.policyTypeName).label}}</div> -->
          <!-- <div class="policyType">{{ announce.policyTypeName }}</div> -->
          <div class="policyMsg">
            <div>{{'·兑现部门：' + announce.redemptionDeptName}}</div>
            <div>{{'·公示日期：' + announce.announceDate}}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import DataBar from './components/dataBar'
import SelectBox from './components/selectBox'
import PolicyFrame from './components/policyFrame'

import config from '@/utils/config.js'
import { formatLabel } from '@/utils/util.js'
import { request } from '../../utils/request'
import { getDoingPolicys, getAnnounces } from "@/common/api/policy.js";

export default {
  name: 'policyCash',
  components: { DataBar, SelectBox, PolicyFrame },
  data() {
    return {
      pageNum: 1,
      pageSize: 10,
      total: 1,
      orderShowDate: 1, //发布时间
      orderPv: 0, //浏览量
      type: null,
      tag: null,
      redemption: null,
      status: null,
      statusOption: [
        {
          label: '全部申报状态',
          value: null,
        },
        {
          label: '申报待开始',
          value: 3,
        },
        {
          label: '申报进行中',
          value: 2,
        },
        {
          label: '申报已结束',
          value: 4,
        },
      ],
      policys: [],
      announces: [],
      crumbs: [
        {
          label: '政策服务',
          value: 'policy',
        },
        {
          label: '政策兑现',
          value: 'policyCash',
          choose: true,
        },
      ],
    }
  },
  methods: {
    /**
     * 判断是否为最后一页
     */
    isLastPage: function () {
      let ns = this
      return ns.pageNum == Math.ceil(ns.total / ns.pageSize)
    },
    /**
     * 上一页
     */
    toPrevPage: function () {
      let ns = this
      if (ns.pageNum <= 1) {
        return
      }
      ns.pageNum--
      ns.getSearchPolicys()
    },
    /**
     * 下一页
     */
    toNextPage: function () {
      let ns = this
      if (ns.isLastPage()) {
        return
      }
      ns.pageNum++
      ns.getSearchPolicys()
    },
    /**
     * 改变页面大小事件
     */
    handleSizeChange: function (e) {
      let ns = this
      ns.pageSize = e
      ns.getSearchPolicys()
    },
    /**
     * 换页事件
     */
    handleCurrentChange: function (e) {
      let ns = this
      ns.pageNum = e
      ns.getSearchPolicys()
    },
    /**
     * 修改发布时间排序
     */
    changeShowDateOrder: function () {
      let ns = this
      ns.orderShowDate++
      ns.orderPv = 0
      ns.getSearchPolicys()
    },
    /**
     * 修改浏览量排序
     */
    changePvOrder: function () {
      let ns = this
      ns.orderPv++
      ns.orderShowDate = 0
      ns.getSearchPolicys()
    },
    /**
     * 修改筛选条件事件
     * @param e 修改后的筛选条件对象
     */
    changeOption: function (e) {
      let ns = this
      ns.type = e.type.id != undefined ? e.type.id : null
      ns.tag = e.tag.id != undefined ? e.tag.id : null
      ns.redemption = e.redemption.id != undefined ? e.redemption.id : null
      ns.getSearchPolicys()
    },
    /**
     * 格式化标签
     * @param label 标签名
     * @return {string|*} 标签名对象
     */
    formatLabel: function (label) {
      return formatLabel(label)
    },
    /**
     * 获取搜索的政策信息
     */
    async getSearchPolicys() {
      let ns = this
      let sortType = null
      let sort = null
      if (ns.orderShowDate > 0) {
        sortType = 1
        sort = ns.orderShowDate % 3
      }
      if (ns.orderPv > 0) {
        sortType = 2
        sort = ns.orderPv % 3
      }
      if (sort == 2) {
        sort = 1
      } else if (sort == 1) {
        sort = 2
      }
      let data = {
        pageNum: ns.pageNum,
        pageSize: ns.pageSize,
        type: ns.type,
        tag: ns.tag,
        redemptionType: ns.redemption,
        status: ns.status,
        sortType: sortType,
        sort: sort,
        entrance: 2,
      }
      let res = await getDoingPolicys(data)
      ns.policys = res.rows
      ns.total = res.total
      for (let i = 0; i < ns.policys.length; i++) {
        ns.policys[i].description = ns.policys[i].description.replace(
          /<[^<>]+>/g,
          ''
        )
      }
    },
    /**
     * 获取兑现结果公示
     */
    async getAnnounces() {
      let ns = this
      ns.announces = []
      let data = {
        pageNum: 1,
        pageSize: 6,
      }
      let res = await getAnnounces(data)
      ns.announces = res.rows
    }
  },
  mounted() {
    let ns = this
    ns.getSearchPolicys()
    ns.getAnnounces()
  },
  activated() {
    let ns = this
    ns.getSearchPolicys()
    ns.getAnnounces()
  },
}
</script>

<style scoped>
.breadcrumb {
  width: 1000px;
  margin-bottom: 30px;
}
.policyDate {
  font-size: 12px;
  color: #999999;
  margin: 0px 5px;
  /* padding-bottom: 5px; */
  padding: 5px 0;
}
.crumbs {
  width: 1200px;
}
#policyDiv {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin: 0 auto;
  width: 1200px;
}

#policyDiv #searchDiv {
  width: 880px;
}

#selectBar {
  height: 50px;
  background-color: #f4f4f4;
  /* width: 840px; */
  border: 1px solid #e1e1e1;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  font-size: 14px;
  color: #606266;
}

#selectBar #leftSelectDiv {
  display: flex;
  justify-content: left;
  align-items: center;
}

#selectBar #leftSelectDiv .selectOptionDiv {
  display: flex;
  align-items: center;
}

#selectBar #leftSelectDiv .selectOptionDiv:hover {
  cursor: pointer;
}

#selectBar #leftSelectDiv .divide {
  margin: 0 20px;
}

#selectBar #rightDiv {
  display: flex;
}

#selectBar #rightDiv .pageBtn {
  background-color: #ffffff;
  margin-left: 10px;
  border: 1px solid #eeeeee;
  width: 40px;
  padding: 8px 0;
  font-size: 20px;
  border-radius: 3px;
  color: #666666;
}

#selectBar #rightDiv .pageCantBtn {
  color: #d4d4d7;
}

#selectBar #rightDiv .pageBtn:hover {
  cursor: pointer;
}

::v-deep #selectBar #rightDiv .el-input__inner {
  border-radius: 0;
}

#policyListDiv {
  width: 880px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
}

#policyListDiv .policyBox {
  width: 430px;
  /* height: 280px; */
  margin-bottom: 20px;
  border: 1px solid #e1e1e1;
  position: relative;
}

#policyPagination {
  margin-bottom: 30px;
  width: 100%;
  text-align: right;
}

#policyDiv #showingDiv {
  width: 260px;
  border: 1px solid #e1e1e1;
  padding: 20px;
  margin-bottom: 30px;
  display: flex;
  flex-direction: column;
}

#policyDiv #showingDiv .showTitle {
  font-weight: bold;
  text-align: left;
  font-size: 20px;
  color: #045db9;
}

#policyDiv #showingDiv .announceDiv {
  padding: 20px 0;
  border-bottom: 1px solid #e1e1e1;
  text-align: left;
}

#policyDiv #showingDiv .announceDiv .policyName {
  font-size: 20px;
  font-weight: bold;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  margin: 5px 0 7px;
}

#policyDiv #showingDiv .announceDiv .policyName:hover {
  cursor: pointer;
  color: #045db9;
  transition: all 0.2s ease 0s;
}

#policyDiv #showingDiv .announceDiv .policyType {
  padding: 5px 10px;
  /* background-color: #f5f2e9;
		color: #f1944f; */
  background: #f4fbff;
  color: #5f89e6;
  display: inline-block;
  margin: 10px 0;
  border-radius: 3px;
}

#policyDiv #showingDiv .announceDiv .policyMsg {
  font-size: 15px;
}

.layout {
  min-height: 100vh;
  position: relative;
  padding-bottom: 150px;
  box-sizing: border-box;
}

.footer {
  position: absolute;
  bottom: 0;
  width: 100%;
}
</style>
